package hc.group;

import javax.servlet.ServletContext;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Import;

import jm.easyconfig.CfgContextUser;

@SpringBootApplication
@Import({ jm.easyconfig.CfgAutoConfiguration.class })
public class BootAppDemoApplication {

	public static void main(String[] args) {
		SpringApplication.run(BootAppDemoApplication.class, args);
	}

	@Autowired
	ApplicationContext applicationContext;
	@Bean
	public CfgContextUser currentUser() {
		return new CfgContextUser() {
			@Override
			public String getUser() {
				ServletContext servletContext = applicationContext.getBean(ServletContext.class);
				Object user = servletContext.getAttribute("user");
				return user == null ? "" : user.toString();
			}
		};

	}

}
